package org.ruoyi.ppt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.ruoyi.ppt.domain.PptImage;
import org.ruoyi.ppt.domain.PptResult;
import org.ruoyi.ppt.domain.PptWithImages;

import java.util.List;

/**
 *
 *
 * @author anran
 * @date 2025/9/30/周二 15:01
 */
@Mapper
public interface PptResultMapper extends BaseMapper<PptResult> {

    /* 1. 先查主表 */
    @Select("SELECT * FROM ppt_results WHERE id = #{pptId} ")
    @Results(id = "pptWithImagesMap", value = {
            @Result(property = "id",        column = "id"),
            @Result(property = "pptTitle",  column = "ppt_title"),
            @Result(property = "introduce", column = "introduce"),
            @Result(property = "pageCount", column = "page_count"),
            @Result(property = "progress",  column = "progress"),
            @Result(property = "status",    column = "status"),
            @Result(property = "noteStatus",column = "note_status"),
            @Result(property = "firstImageUpAt", column = "first_image_up_at"),
            @Result(property = "createdAt", column = "created_at"),
            @Result(property = "updatedAt", column = "updated_at"),
            @Result(property = "stateDescription", column = "state_description"),
            @Result(property = "processUrl",column = "process_url"),
            @Result(property = "previewUrl",column = "preview_url"),
            /* 2. 再查子表，自动封装成 List */
            @Result(property = "images", column = "id",
                    many = @Many(select = "findImagesByPptId"))
    })
    PptWithImages selectPptWithImages(@Param("pptId") String pptId);

    /* 3. 子查询 */
    @Select("SELECT id, ppt_id, image_url, upload_time " +
            "FROM ppt_images " +
            "WHERE ppt_id = #{pptId}")
    List<PptImage> findImagesByPptId(@Param("pptId") String pptId);

}
